home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Archives / ARexxTools / postjet.lha / postjet.rexx < prev    next >
Encoding:
OS/2 REXX Batch file  |  1996-02-20  |  3.9 KB  |  230 lines

  1. /*
  2.     PostJet
  3. */
  4.  
  5. /*
  6.     Getprefs
  7. */
  8. if open(p,'env:postjet.prefs','R') then do
  9.     guifile=readln(p)
  10.     guifile=guifile||'/postjet.gui'
  11.     printer=readln(p)
  12.     pagesize=readln(p)
  13.     initfile=readln(p)
  14.     useropts=readln(p)
  15.     call close(p)
  16. end
  17. else do
  18.     say "Cannot open preference file."
  19.     exit
  20. end
  21.  
  22. select
  23.     when printer='deskjet' then baseopts='-j0'
  24.     when printer='laserjet' then baseopts='-j2'
  25.     otherwise do
  26.         say 'Config file error - line 1 : printer name'
  27.         exit
  28.     end
  29. end
  30.  
  31. select
  32.     when pagesize='letter' then baseopts=baseopts||' -s0'
  33.     when pagesize='legal' then baseopts=baseopts||' -s1'
  34.     when pagesize='a4' then baseopts=baseopts||' -s3'
  35.     otherwise do
  36.         say 'Config file error - line 2 : paper type'
  37.         exit
  38.     end
  39. end
  40.  
  41. /*
  42.     Open support library
  43. */
  44. if ~show("L","rexxsupport.library") then
  45.     if ~addlib('rexxsupport.library',0,-30,0) then do
  46.         say "Cannot open rexxsupport.library"
  47.         exit
  48.     end
  49.  
  50. /*
  51.     Launch varexx server
  52. */
  53. if ~show('p','VAREXX') then do
  54.     address command 'run >nil: varexx'
  55.     waitforport VAREXX
  56. end
  57.  
  58. /*
  59.     VAREXX default port
  60. */
  61. address VAREXX
  62.  
  63. /*
  64.     Create message port for the window
  65. */
  66. call OPENPORT('POSTJETWIN')
  67.  
  68. /*
  69.     Load gui
  70. */
  71. options results
  72. 'load' guifile 'POSTJETWIN'
  73.  
  74. /*
  75.     Get window port
  76. */
  77. port=result
  78. address value port
  79.  
  80. /*
  81.     Show window
  82. */
  83. show
  84.  
  85. /*
  86.     Prepare variables
  87. */
  88. filename='NONE'
  89. pageno='0'
  90.  
  91. /*
  92.     Message loop
  93. */
  94. do until message = CLOSEWINDOW
  95.  
  96.     /*
  97.         Wait for a packet
  98.     */
  99.     call WAITPKT("POSTJETWIN")
  100.     packet=GETPKT("POSTJETWIN")
  101.  
  102.     /*
  103.         If packet exists get the message
  104.     */
  105.     if packet ~= '00000000'x then do
  106.         message=GETARG(packet)
  107.  
  108.         /*
  109.             Make proper action
  110.         */
  111.         select
  112.  
  113.             when message=PRINTODDPAGES then do
  114.                     if filename~='NONE' then do
  115.                         'busy set'
  116.                         pn=pagenumbers()
  117.                         do i=1 to pn by 2
  118.                             say 'Printing page' i 'of file' filename
  119.                             opts=baseopts||' -b'||i||'e'||i||' '||' '||initfile||' '||filename
  120.                             address command 'postlj >nil: '||opts
  121.                         end
  122.                         'busy'
  123.                     end
  124.                 end
  125.  
  126.             when message=PRINTEVENPAGES then do
  127.                     if filename~='NONE' then do
  128.                         'busy set'
  129.                         pn=pagenumbers()
  130.                         do i=2 to pn by 2
  131.                             say 'Printing page' i 'of file' filename
  132.                             opts=baseopts||' -b'||i||'e'||i||' '||' '||initfile||' '||filename
  133.                             address command 'postlj >nil: '||opts
  134.                         end
  135.                         'busy'
  136.                     end
  137.                 end
  138.  
  139.             when message=PRINTSINGLEPAGE then do
  140.                     if filename~='NONE' then do
  141.                         'busy set'
  142.                         pn=pagenumbers()
  143.                         if ((pageno>0)&(pageno<=pn)) then do
  144.                             say 'Printing page' pageno 'of file' filename
  145.                             opts=baseopts||' -b'||pageno||'e'||pageno||' '||' '||initfile||' '||filename
  146.                             say 'postlj '||opts
  147.                             address command 'postlj >nil: '||opts
  148.                         end
  149.                         'busy'
  150.                     end
  151.                 end
  152.  
  153.             when message=GETPOSTFILENAME then do
  154.                     address command 'requestfile >t:pjgfntf'
  155.                     open(t,"t:pjgfntf",'R')
  156.                     filename=strip(readln(t),'B','"')
  157.                     call close(t)
  158.                     address command 'delete >nil: t:pjgfntf'
  159.                     'settext POSTFILENAME' filename
  160.                 end
  161.  
  162.             when word(message,1)=POSTFILENAME then filename=word(message,2)
  163.  
  164.             when word(message,1)=PAGENUMBER then pageno=word(message,2)
  165.  
  166.             otherwise if message~=CLOSEWINDOW then do
  167.                 say 'Internal error in main loop. Please mail these informations'
  168.                 say 'to the author:'
  169.                 say 'MAIN WIN LOOP - OTHERWISE - MESSAGE:' message
  170.                 exit
  171.             end
  172.  
  173.         end
  174.  
  175.     end
  176.  
  177. end
  178.  
  179. /*
  180.     Close window
  181. */
  182. 'hide unload'
  183.  
  184. /*
  185.     Close message port
  186. */
  187. call CLOSEPORT("POSTJETWIN")
  188.  
  189. /*
  190.     Close varexx server
  191. */
  192. address command 'vxc >nil:'
  193.  
  194. /*
  195.     Exit
  196. */
  197. exit
  198.  
  199. pagenumbers:
  200.  
  201.     if ~open(t,filename,'R') then do
  202.         return 0
  203.     end
  204.  
  205.     close(t)
  206.  
  207.     address command 'search from '||filename||' search "%%Pages:" >ram:spnff'
  208.  
  209.     if ~open(t,"ram:spnff",'R') then do
  210.         return 0
  211.     end
  212.  
  213.     do forever
  214.         riga=readln(t)
  215.         riga=word(riga,3)
  216.  
  217.         w=verify(riga,"1234567890")
  218.         do while w~==0
  219.             riga=substr(riga,1,w-1)||substr(riga,w+1,length(riga)-w)
  220.             w=verify(riga,"1234567890")
  221.         end
  222.  
  223.         if riga~=="" then return riga
  224.  
  225.         if eof(t) then do
  226.             close(t)
  227.             return 0
  228.         end
  229.     end
  230.